<style type="text/css">
    .table thead th {
        vertical-align: middle;
    }
    table td.ayat-arabic {
        font-family: myFirstFont;
        text-align: center;
        font-size: 25px;
        letter-spacing: 1px;
        vertical-align: middle;
        weight: 10%;
        line-height:40px;
    }
    table td.ayat {
        text-align: center;
        vertical-align: middle;
        weight: 10%;
        line-height:40px;
    }
</style>
        

<?php 

$preProses      = new PreProcessing($pdo);
$rulePertanyaan = new RulePertanyaanTiga($pdo);

$stemmerFactory = new \Sastrawi\Stemmer\StemmerFactory();
$stemmer        = $stemmerFactory->createStemmer();
$lastResult     = $rulePertanyaan->qas($_SESSION['keyword']);

if (!is_array($lastResult['data'])):
    echo $lastResult['data'];
endif;
?>
<?php 
if (is_array($lastResult['data'])): 
$result = $lastResult['data'];
$listNamaSuratIndonesia = $lastResult['namaSurat']['indonesia'];
$listNamaSuratArabic = $lastResult['namaSurat']['arabic'];
?>
<table class="table table-striped">
    <thead>
        <tr>
            <th rowspan="2" class="head-table">No</th>
            <th rowspan="2" class="head-table">Ayat</th>
            <th colspan="2" class="head-table score-detail">Scoring</th>
            <th rowspan="2" class="head-table score-detail">Total Score</th>
        </tr>
        <tr class="score-detail" >
            <th class="head-table" style="min-width:125px;">Wordmatch</th>
            <th class="head-table" style="min-width:125px;">Rule</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $no = 1;
        foreach ($result as $dataResult) :
            ?>
            <tr>
                <td style="text-align: center"><?php echo $no; ?></td>
                <td>
                <?php
                    foreach ($dataResult['data'] as $jenis => $data) :
                        if ($jenis == 'arabic'):
                            echo '<div class="arabic" style="display: inline-block; float:right">';
                            echo $data;
                            echo '</div>';
                            echo '<div class="arabic" style="display: inline-block">( '.$listNamaSuratArabic[$dataResult['sura']].' : '.angkaToArabic($dataResult['aya']).' )</div>';
                        endif;
                    endforeach;
                    
                    echo '<br/>';
                    foreach ($dataResult['data'] as $jenis => $data) :
                        if ($jenis == 'indonesia'):
                            echo $data.' ( '.$listNamaSuratIndonesia[$dataResult['sura']].' : '.$dataResult['aya'].' )';
                        endif;
                    endforeach;
                ?>
                </td>
                <td class="score-detail">
                <?php
                    foreach ($dataResult['data'] as $jenis => $data) :
                        if ($jenis == 'wordmatch'):
                            foreach ($data as $kata => $value) {
                                echo $kata.' : '.$value['score'].'<br/>';
                            }
                        endif;
                    endforeach; //end for dataSura
                ?>
                </td>
                <td class="score-detail">
                <?php
                    foreach ($dataResult['data'] as $jenis => $data) :
                        if ($jenis == 'rule1' || $jenis == 'rule2' || $jenis == 'rule3' || $jenis == 'rule4'):
                            echo $jenis.'<br/>';
                            foreach ($data as $kata => $value) {
                                echo $kata.' : '.$value['score'].'<br/>';
                            }
                            echo '<br/>';
                        endif;
                    endforeach; //end for dataSura
                ?>
                </td>
                <td class="score-detail">
                <?php
                    foreach ($dataResult['data'] as $jenis => $data) :
                        if ($jenis == 'total'):
                            echo $data;
                        endif;
                    endforeach;
                ?>
                </td>
            </tr>
            <?php
            $no++;
        endforeach;
        ?>
    </tbody>
</table>
<?php endif; ?>
